<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: ActiveRecord::ConnectionAdapters::ConnectionPool</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">ActiveRecord::ConnectionAdapters::ConnectionPool</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../files/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool_rb.html">
                vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                <a href="../../Object.html">
                Object
               </a>
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
Connection pool base class for managing ActiveRecord database connections.
</p>
<h2>Introduction</h2>
<p>
A <a href="ConnectionPool.html#M001599">connection</a> pool synchronizes
thread access to a limited number of database connections. The basic idea
is that each thread checks out a database <a
href="ConnectionPool.html#M001599">connection</a> from the pool, uses that
<a href="ConnectionPool.html#M001599">connection</a>, and checks the <a
href="ConnectionPool.html#M001599">connection</a> back in. <a
href="ConnectionPool.html">ConnectionPool</a> is completely thread-safe,
and will ensure that a <a href="ConnectionPool.html#M001599">connection</a>
cannot be used by two threads at the same time, as long as <a
href="ConnectionPool.html">ConnectionPool</a>&#8216;s contract is correctly
followed. It will also handle cases in which there are more threads than
connections: if all connections have been checked out, and a thread tries
to <a href="ConnectionPool.html#M001606">checkout</a> a <a
href="ConnectionPool.html#M001599">connection</a> anyway, then <a
href="ConnectionPool.html">ConnectionPool</a> will wait until some other
thread has checked in a <a
href="ConnectionPool.html#M001599">connection</a>.
</p>
<h2>Obtaining (checking out) a <a href="ConnectionPool.html#M001599">connection</a></h2>
<p>
Connections can be obtained and used from a <a
href="ConnectionPool.html#M001599">connection</a> pool in several ways:
</p>
<ol>
<li>Simply use <a href="../Base.html#M001773">ActiveRecord::Base.connection</a>
as with ActiveRecord 2.1 and earlier (pre-<a
href="ConnectionPool.html#M001599">connection</a>-pooling). Eventually,
when you&#8216;re done with the <a
href="ConnectionPool.html#M001599">connection</a>(s) and wish it to be
returned to the pool, you call
ActiveRecord::Base.clear_active_connections!. This will be the default
behavior for ActiveRecord when used in conjunction with ActionPack&#8216;s
request handling cycle.

</li>
<li>Manually check out a <a href="ConnectionPool.html#M001599">connection</a>
from the pool with <a
href="../Base.html#M001780">ActiveRecord::Base.connection_pool</a>.<a
href="ConnectionPool.html#M001606">checkout</a>. You are responsible for
returning this <a href="ConnectionPool.html#M001599">connection</a> to the
pool when finished by calling <a
href="../Base.html#M001780">ActiveRecord::Base.connection_pool</a>.<a
href="ConnectionPool.html#M001607">checkin</a>(<a
href="ConnectionPool.html#M001599">connection</a>).

</li>
<li>Use <a
href="../Base.html#M001780">ActiveRecord::Base.connection_pool</a>.<a
href="ConnectionPool.html#M001601">with_connection</a>(&amp;block), which
obtains a <a href="ConnectionPool.html#M001599">connection</a>, yields it
as the sole argument to the block, and returns it to the pool after the
block completes.

</li>
</ol>
<p>
Connections in the pool are actually <a
href="AbstractAdapter.html">AbstractAdapter</a> objects (or objects
compatible with <a href="AbstractAdapter.html">AbstractAdapter</a>&#8216;s
interface).
</p>
<h2>Options</h2>
<p>
There are two <a
href="ConnectionPool.html#M001599">connection</a>-pooling-related options
that you can add to your database <a
href="ConnectionPool.html#M001599">connection</a> configuration:
</p>
<ul>
<li><tt>pool</tt>: number indicating size of <a
href="ConnectionPool.html#M001599">connection</a> pool (default 5)

</li>
<li><tt>wait_timeout</tt>: number of seconds to block and wait for a <a
href="ConnectionPool.html#M001599">connection</a> before giving up and
raising a timeout error (default 5 seconds).

</li>
</ul>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M001607">checkin</a>&nbsp;&nbsp;
      <a href="#M001606">checkout</a>&nbsp;&nbsp;
      <a href="#M001604">clear_reloadable_connections!</a>&nbsp;&nbsp;
      <a href="#M001605">clear_stale_cached_connections!</a>&nbsp;&nbsp;
      <a href="#M001602">connected?</a>&nbsp;&nbsp;
      <a href="#M001599">connection</a>&nbsp;&nbsp;
      <a href="#M001603">disconnect!</a>&nbsp;&nbsp;
      <a href="#M001598">new</a>&nbsp;&nbsp;
      <a href="#M001600">release_connection</a>&nbsp;&nbsp;
      <a href="#M001601">with_connection</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





    <div id="attribute-list">
      <h3 class="section-bar">Attributes</h3>

      <div class="name-list">
        <table>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">spec</td>
          <td class="context-item-value">&nbsp;[R]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        </table>
      </div>
    </div>
      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M001598" class="method-detail">
        <a name="M001598"></a>

        <div class="method-heading">
          <a href="#M001598" class="method-signature">
          <span class="method-name">new</span><span class="method-args">(spec)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Creates a <a href="ConnectionPool.html#M001598">new</a> <a
href="ConnectionPool.html">ConnectionPool</a> object. <tt>spec</tt> is a
ConnectionSpecification object which describes database <a
href="ConnectionPool.html#M001599">connection</a> information (e.g.
adapter, host name, username, password, etc), as well as the maximum size
for this <a href="ConnectionPool.html">ConnectionPool</a>.
</p>
<p>
The default <a href="ConnectionPool.html">ConnectionPool</a> maximum size
is 5.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001598-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001598-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb, line 66</span>
66:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">spec</span>)
67:         <span class="ruby-ivar">@spec</span> = <span class="ruby-identifier">spec</span>
68: 
69:         <span class="ruby-comment cmt"># The cache of reserved connections mapped to threads</span>
70:         <span class="ruby-ivar">@reserved_connections</span> = {}
71: 
72:         <span class="ruby-comment cmt"># The mutex used to synchronize pool access</span>
73:         <span class="ruby-ivar">@connection_mutex</span> = <span class="ruby-constant">Monitor</span>.<span class="ruby-identifier">new</span>
74:         <span class="ruby-ivar">@queue</span> = <span class="ruby-ivar">@connection_mutex</span>.<span class="ruby-identifier">new_cond</span>
75: 
76:         <span class="ruby-comment cmt"># default 5 second timeout unless on ruby 1.9</span>
77:         <span class="ruby-ivar">@timeout</span> =
78:           <span class="ruby-keyword kw">if</span> <span class="ruby-constant">RUBY_VERSION</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value str">'1.9'</span>
79:             <span class="ruby-identifier">spec</span>.<span class="ruby-identifier">config</span>[<span class="ruby-identifier">:wait_timeout</span>] <span class="ruby-operator">||</span> <span class="ruby-value">5</span>
80:           <span class="ruby-keyword kw">end</span>
81: 
82:         <span class="ruby-comment cmt"># default max pool size to 5</span>
83:         <span class="ruby-ivar">@size</span> = (<span class="ruby-identifier">spec</span>.<span class="ruby-identifier">config</span>[<span class="ruby-identifier">:pool</span>] <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">spec</span>.<span class="ruby-identifier">config</span>[<span class="ruby-identifier">:pool</span>].<span class="ruby-identifier">to_i</span>) <span class="ruby-operator">||</span> <span class="ruby-value">5</span>
84: 
85:         <span class="ruby-ivar">@connections</span> = []
86:         <span class="ruby-ivar">@checked_out</span> = []
87:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M001607" class="method-detail">
        <a name="M001607"></a>

        <div class="method-heading">
          <a href="#M001607" class="method-signature">
          <span class="method-name">checkin</span><span class="method-args">(conn)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Check-in a database <a href="ConnectionPool.html#M001599">connection</a>
back into the pool, indicating that you no longer need this <a
href="ConnectionPool.html#M001599">connection</a>.
</p>
<p>
<tt>conn</tt>: an <a href="AbstractAdapter.html">AbstractAdapter</a>
object, which was obtained by earlier by calling <tt><a
href="ConnectionPool.html#M001606">checkout</a></tt> on this pool.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001607-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001607-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb, line 210</span>
210:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">checkin</span>(<span class="ruby-identifier">conn</span>)
211:         <span class="ruby-ivar">@connection_mutex</span>.<span class="ruby-identifier">synchronize</span> <span class="ruby-keyword kw">do</span>
212:           <span class="ruby-identifier">conn</span>.<span class="ruby-identifier">run_callbacks</span> <span class="ruby-identifier">:checkin</span>
213:           <span class="ruby-ivar">@checked_out</span>.<span class="ruby-identifier">delete</span> <span class="ruby-identifier">conn</span>
214:           <span class="ruby-ivar">@queue</span>.<span class="ruby-identifier">signal</span>
215:         <span class="ruby-keyword kw">end</span>
216:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001606" class="method-detail">
        <a name="M001606"></a>

        <div class="method-heading">
          <a href="#M001606" class="method-signature">
          <span class="method-name">checkout</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Check-out a database <a href="ConnectionPool.html#M001599">connection</a>
from the pool, indicating that you want to use it. You should call <a
href="ConnectionPool.html#M001607">checkin</a> when you no longer need
this.
</p>
<p>
This is done by either returning an existing <a
href="ConnectionPool.html#M001599">connection</a>, or by creating a <a
href="ConnectionPool.html#M001598">new</a> <a
href="ConnectionPool.html#M001599">connection</a>. If the maximum number of
connections for this pool has already been reached, but the pool is empty
(i.e. they&#8216;re all being used), then this method will wait until a
thread has checked in a <a
href="ConnectionPool.html#M001599">connection</a>. The wait time is bounded
however: if no <a href="ConnectionPool.html#M001599">connection</a> can be
checked out within the timeout specified for this pool, then a <a
href="../ConnectionTimeoutError.html">ConnectionTimeoutError</a> exception
will be raised.
</p>
<p>
Returns: an <a href="AbstractAdapter.html">AbstractAdapter</a> object.
</p>
<p>
Raises:
</p>
<ul>
<li><a href="../ConnectionTimeoutError.html">ConnectionTimeoutError</a>: no <a
href="ConnectionPool.html#M001599">connection</a> can be obtained from the
pool within the timeout period.

</li>
</ul>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001606-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001606-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb, line 181</span>
181:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">checkout</span>
182:         <span class="ruby-comment cmt"># Checkout an available connection</span>
183:         <span class="ruby-ivar">@connection_mutex</span>.<span class="ruby-identifier">synchronize</span> <span class="ruby-keyword kw">do</span>
184:           <span class="ruby-identifier">loop</span> <span class="ruby-keyword kw">do</span>
185:             <span class="ruby-identifier">conn</span> = <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@checked_out</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">&lt;</span> <span class="ruby-ivar">@connections</span>.<span class="ruby-identifier">size</span>
186:                      <span class="ruby-identifier">checkout_existing_connection</span>
187:                    <span class="ruby-keyword kw">elsif</span> <span class="ruby-ivar">@connections</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">&lt;</span> <span class="ruby-ivar">@size</span>
188:                      <span class="ruby-identifier">checkout_new_connection</span>
189:                    <span class="ruby-keyword kw">end</span>
190:             <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">conn</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conn</span>
191:             <span class="ruby-comment cmt"># No connections available; wait for one</span>
192:             <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@queue</span>.<span class="ruby-identifier">wait</span>(<span class="ruby-ivar">@timeout</span>)
193:               <span class="ruby-keyword kw">next</span>
194:             <span class="ruby-keyword kw">else</span>
195:               <span class="ruby-comment cmt"># try looting dead threads</span>
196:               <span class="ruby-identifier">clear_stale_cached_connections!</span>
197:               <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@size</span> <span class="ruby-operator">==</span> <span class="ruby-ivar">@checked_out</span>.<span class="ruby-identifier">size</span>
198:                 <span class="ruby-identifier">raise</span> <span class="ruby-constant">ConnectionTimeoutError</span>, <span class="ruby-node">&quot;could not obtain a database connection#{&quot; within #{@timeout} seconds&quot; if @timeout}.  The max pool size is currently #{@size}; consider increasing it.&quot;</span>
199:               <span class="ruby-keyword kw">end</span>
200:             <span class="ruby-keyword kw">end</span>
201:           <span class="ruby-keyword kw">end</span>
202:         <span class="ruby-keyword kw">end</span>
203:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001604" class="method-detail">
        <a name="M001604"></a>

        <div class="method-heading">
          <a href="#M001604" class="method-signature">
          <span class="method-name">clear_reloadable_connections!</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Clears the cache which maps classes
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001604-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001604-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb, line 137</span>
137:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">clear_reloadable_connections!</span>
138:         <span class="ruby-ivar">@reserved_connections</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">name</span>, <span class="ruby-identifier">conn</span><span class="ruby-operator">|</span>
139:           <span class="ruby-identifier">checkin</span> <span class="ruby-identifier">conn</span>
140:         <span class="ruby-keyword kw">end</span>
141:         <span class="ruby-ivar">@reserved_connections</span> = {}
142:         <span class="ruby-ivar">@connections</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">conn</span><span class="ruby-operator">|</span>
143:           <span class="ruby-identifier">conn</span>.<span class="ruby-identifier">disconnect!</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conn</span>.<span class="ruby-identifier">requires_reloading?</span>
144:         <span class="ruby-keyword kw">end</span>
145:         <span class="ruby-ivar">@connections</span> = []
146:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001605" class="method-detail">
        <a name="M001605"></a>

        <div class="method-heading">
          <a href="#M001605" class="method-signature">
          <span class="method-name">clear_stale_cached_connections!</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Return any checked-out connections back to the pool by threads that are no
longer alive.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001605-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001605-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb, line 159</span>
159:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">clear_stale_cached_connections!</span>
160:         <span class="ruby-identifier">remove_stale_cached_threads!</span>(<span class="ruby-ivar">@reserved_connections</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">name</span>, <span class="ruby-identifier">conn</span><span class="ruby-operator">|</span>
161:           <span class="ruby-identifier">checkin</span> <span class="ruby-identifier">conn</span>
162:         <span class="ruby-keyword kw">end</span>
163:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001602" class="method-detail">
        <a name="M001602"></a>

        <div class="method-heading">
          <a href="#M001602" class="method-signature">
          <span class="method-name">connected?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns true if a <a href="ConnectionPool.html#M001599">connection</a> has
already been opened.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001602-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001602-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb, line 120</span>
120:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">connected?</span>
121:         <span class="ruby-operator">!</span><span class="ruby-ivar">@connections</span>.<span class="ruby-identifier">empty?</span>
122:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001599" class="method-detail">
        <a name="M001599"></a>

        <div class="method-heading">
          <a href="#M001599" class="method-signature">
          <span class="method-name">connection</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Retrieve the <a href="ConnectionPool.html#M001599">connection</a>
associated with the current thread, or call <a
href="ConnectionPool.html#M001606">checkout</a> to obtain one if necessary.
</p>
<p>
<a href="ConnectionPool.html#M001599">connection</a> can be called any
number of times; the <a href="ConnectionPool.html#M001599">connection</a>
is held in a hash keyed by the thread id.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001599-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001599-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb, line 94</span>
 94:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">connection</span>
 95:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conn</span> = <span class="ruby-ivar">@reserved_connections</span>[<span class="ruby-identifier">current_connection_id</span>]
 96:           <span class="ruby-identifier">conn</span>
 97:         <span class="ruby-keyword kw">else</span>
 98:           <span class="ruby-ivar">@reserved_connections</span>[<span class="ruby-identifier">current_connection_id</span>] = <span class="ruby-identifier">checkout</span>
 99:         <span class="ruby-keyword kw">end</span>
100:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001603" class="method-detail">
        <a name="M001603"></a>

        <div class="method-heading">
          <a href="#M001603" class="method-signature">
          <span class="method-name">disconnect!</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Disconnects all connections in the pool, and clears the pool.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001603-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001603-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb, line 125</span>
125:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">disconnect!</span>
126:         <span class="ruby-ivar">@reserved_connections</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">name</span>,<span class="ruby-identifier">conn</span><span class="ruby-operator">|</span>
127:           <span class="ruby-identifier">checkin</span> <span class="ruby-identifier">conn</span>
128:         <span class="ruby-keyword kw">end</span>
129:         <span class="ruby-ivar">@reserved_connections</span> = {}
130:         <span class="ruby-ivar">@connections</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">conn</span><span class="ruby-operator">|</span>
131:           <span class="ruby-identifier">conn</span>.<span class="ruby-identifier">disconnect!</span>
132:         <span class="ruby-keyword kw">end</span>
133:         <span class="ruby-ivar">@connections</span> = []
134:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001600" class="method-detail">
        <a name="M001600"></a>

        <div class="method-heading">
          <a href="#M001600" class="method-signature">
          <span class="method-name">release_connection</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Signal that the thread is finished with the current <a
href="ConnectionPool.html#M001599">connection</a>. <a
href="ConnectionPool.html#M001600">release_connection</a> releases the <a
href="ConnectionPool.html#M001599">connection</a>-thread association and
returns the <a href="ConnectionPool.html#M001599">connection</a> to the
pool.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001600-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001600-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb, line 105</span>
105:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">release_connection</span>
106:         <span class="ruby-identifier">conn</span> = <span class="ruby-ivar">@reserved_connections</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">current_connection_id</span>)
107:         <span class="ruby-identifier">checkin</span> <span class="ruby-identifier">conn</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conn</span>
108:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001601" class="method-detail">
        <a name="M001601"></a>

        <div class="method-heading">
          <a href="#M001601" class="method-signature">
          <span class="method-name">with_connection</span><span class="method-args">() {|conn| ...}</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Reserve a <a href="ConnectionPool.html#M001599">connection</a>, and yield
it to a block. Ensure the <a
href="ConnectionPool.html#M001599">connection</a> is checked back in when
finished.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001601-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001601-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb, line 112</span>
112:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">with_connection</span>
113:         <span class="ruby-identifier">conn</span> = <span class="ruby-identifier">checkout</span>
114:         <span class="ruby-keyword kw">yield</span> <span class="ruby-identifier">conn</span>
115:       <span class="ruby-keyword kw">ensure</span>
116:         <span class="ruby-identifier">checkin</span> <span class="ruby-identifier">conn</span>
117:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>